package com.lyhlmj.oop_client.Frames.WaitFrame;

import com.lyhlmj.oop_client.ClientOperation.ClientUtil.Client;
import com.lyhlmj.oop_client.Style.Buttons.GeneralButton;
import com.lyhlmj.oop_client.Style.Buttons.WaitFrameButton.LogoutButton;
import com.lyhlmj.oop_client.Style.Buttons.WaitFrameButton.ReadyButton;
import com.lyhlmj.oop_client.Utils.GetScreenSize;

import javax.swing.*;
import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class WaitFrameButtonPanels extends JPanel {
    private Client client = Client.client;
    private Window owner;
    private ReadyButton readyButton;
    private LogoutButton logoutButton;
    private GeneralButton aboutButton;
    //  得到Frame的大小
    int width = GetScreenSize.getFitSize()[0];
    int height = GetScreenSize.getFitSize()[1];

    public WaitFrameButtonPanels(Window owner) {
        this.owner = owner;
        this.initialButton();
    }

    public void initialButton() {
        readyButton = new ReadyButton("开始游戏", owner);
        readyButton.setPreferredSize(new Dimension((int)(0.2 * width),(int)(0.02 * width)));
        aboutButton = new GeneralButton("关于作者");
        aboutButton.setPreferredSize(new Dimension((int)(0.2 * width),(int)(0.02 * width)));
        logoutButton = new LogoutButton("退出游戏", owner);
        logoutButton.setPreferredSize(new Dimension((int)(0.2 * width),(int)(0.02 * width)));
        this.setOpaque(false);
        this.add(readyButton);
        this.add(aboutButton);
        this.add(logoutButton);
    }

    //    添加按钮的点击事件
    public void setButtonFunction() {
        readyButton.addActionListener(e -> {  //添加按钮单击事件（lambda表达式形式
            readyButton.doReady();
        });
        aboutButton.addActionListener(e -> {
            JOptionPane.showMessageDialog(owner, "开发人员：（山东大学软工5班）李雨翰、李玫洁");
        });
        logoutButton.addActionListener(e -> {
            logoutButton.doLogout();
        });
    }
}
